<!--
 * @name: 
 * @Author: 刘大可
 * @Date: 2023-08-22 15:48:05
 * @LastEditors: 刘大可
 * @LastEditTime: 2023-08-22 19:43:51
-->
<template>
  <div class="school-comment">
   
    <view class="comments margin-top">
      <block v-for="(item,index) in commentList" :key="index">
        <view class="comment margin-lr margin-bottom-sm bg-white">
          <view class="userInfo row">
            <image
              class="avatar margin-right"
              :src="item.user.avatar"
              mode="scaleToFill"
            />
            {{ item.user.nickname }}
          </view>
          <view class="content">
            {{ item.content }}
          </view>
          <view class="images">
            <block v-for="(img,index) in item.image" :key="index">
               <image
               @click="fd(img)"
                 class="img"
                :src="img"
                mode="scaleToFill"
              />
            </block>
          </view>

          <block v-for="(ctem,index) in item.comment" :key="index">
            <view class="commenth">
              商家回复:{{ ctem.content }}
            </view>
          </block>
          <view class="cuIcon-roundclose close" @click="del(item.id)" v-if="type == 1"></view>
          <view class="hui" @click="go('/uni_modules/school-comment/pages/edit/index?'+ `b_id=${item.b_id}&o_id=${item.o_id}&pid=${item.id}`)" v-if="type==1&&item.comment.length==0">回复</view>
        </view>
      </block>
    </view>
    <view class="row margin-tb-lg" style="justify-content: center;" @click="nextPage">查看更多
    
      <view class="cuIcon-unfold"></view>
    
    </view>
    <view class="bt"></view>
  </div>
</template>

<script>
export default {
  name: "school-comment",
  props: {
    type:{
      type:String
    },
    bid: {
      type: String,
    },
  },
  data() {
    return {
      page:1,
      commentList:[
        
      ]
    }
  },
  computed: {},
  methods: {
    nextPage(){
      this.getData(this.page+1)

    },
    del(id){
      this.tips.choose("确定删除该评论吗？").then(res=>{
        console.log(res);
        if (res.code==200) {

          this.request("ZhBusinesss/comment_del",{
            b_id:this.bid, id,
            type:2
          }).then(res=>{
            if (res.data.status==200) {
              this.tips.success("删除成功")
              this.getData()
            }
          })

        }
      })

    },
    getData(page=1){
      this.page=page
      this.request("ZhBusinesss/comment", {
        page,
        b_id: this.bid
      }).then(res => {
        console.log(res.data.data.data);
        if (res.data.data) {
          this.commentList = page==1?[
            ...res.data.data.data
          ]:[
            ...this.commentList,
            ...res.data.data.data
          ]

          if (res.data.data.data.length==0&&page!=1) {
            this.tips.tips("没有更多评论了！")
          }
        }
      })
    }

  },
  watch: {},
  created() {
      this.getData()
  },
  // 组件周期函数--监听组件挂载完毕
  mounted() {
   
  },
  // 组件周期函数--监听组件数据更新之前
  beforeUpdate() {},
  // 组件周期函数--监听组件数据更新之后
  updated() {},
  // 组件周期函数--监听组件激活(显示)
  activated() {},
  // 组件周期函数--监听组件停用(隐藏)
  deactivated() {},
  // 组件周期函数--监听组件销毁之前
  beforeDestroy() {},
}
</script>

<style  lang="scss">
  @import "./main.scss";
</style>